package main

import (
	"fmt"
	"go-rpc/service"
	"log"
	"net"
	"net/rpc"
	"net/rpc/jsonrpc"
)

func main() {

	conn, err := net.Dial("tcp", "localhost:9091") // 进行拨号

	if err != nil {
		log.Fatal("dialing:", err) // 拨号失败

	}

	client := rpc.NewClientWithCodec(jsonrpc.NewClientCodec(conn))
	args := &service.Args{10, 20} // 制造请求参数

	var reply int

	err = client.Call("ServiceA.Add", args, &reply)
	if err != nil {
		log.Fatal("Service.Add error:", err)

	}

	fmt.Printf("ServiceA.Add: %d+%d=%d\n", args.X, args.Y, reply)

}
